 package handling.cashshop.handler;



import client.MapleCharacter;
import client.MapleCharacterUtil;
import client.MapleClient;
import client.MapleQuestStatus;
import client.inventory.*;
import com.alibaba.druid.pool.DruidPooledConnection;
import configs.ServerConfig;
import constants.ItemConstants;
import database.DatabaseConnection;
import handling.channel.ChannelServer;
import handling.world.WorldFindService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import server.AutobanManager;
import server.MapleInventoryManipulator;
import server.MapleItemInformationProvider;
import server.cashshop.CashItemFactory;
import server.cashshop.CashItemInfo;
import server.cashshop.CashShop;
import server.quest.MapleQuest;
import tools.*;
import tools.data.input.LittleEndianAccessor;
import tools.packet.MTSCSPacket;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;








































 public class BuyCashItemHandler {
/*  43 */   private static final Logger log = LogManager.getLogger(BuyCashItemHandler.class.getName()); public static void BuyCashItem(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) throws SQLException { int n, wishlist[], m, k; Item item1; int cashId, j, snCsId; CashItemInfo item; int snCS; long uniqueId; int snID; byte toCharge; int i6, i, i5, coupon, i4, sn; Item item2; int itemid, i3, i2, i1; CashItemInfo cashItemInfo1; int count; CashItemInfo cItem, cashItemInfo5, cashItemInfo4; MapleInventoryType type; Item item3; CashItemInfo cashItemInfo3; String partnerName; Item boxItem; CashItemInfo cashItemInfo2; int slots; MapleQuestStatus marr; Item item4; int i7; String str1; List<Integer> packageIds; String msg; List<Pair<Integer, Integer>> boxItemSNs; int price; CashItemInfo cashItemInfo6; String str2; Map<Integer, Item> packageItems; Triple<Integer, Integer, Integer> info; Pair<Integer, Integer> pair; int Money; Triple<Integer, Integer, Integer> triple1;
     Iterator<Integer> iterator;
     CashItemInfo cashItemInfo7;
/*  46 */     int action = slea.readByte() & 0xFF;
/*  47 */     CashShop cs = chr.getCashInventory();
/*  48 */     CashItemFactory cashinfo = CashItemFactory.getInstance();
/*  49 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/*  50 */     switch (action) {

       case 3:
/*  53 */         n = slea.readByte() + 1;
/*  54 */         slea.skip(2);
/*  55 */         i6 = slea.readInt();


/*  58 */         if (n == 2 && !ServerConfig.CHANNEL_ENABLEPOINTSBUY) {
/*  59 */           chr.dropMessage(1, "此商品无法使用抵用券购买，请选择其他商品吧。");
/*  60 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/*  63 */         cashItemInfo5 = cashinfo.getItem(i6);
/*  64 */         if (chr.isShowPacket()) {
/*  65 */           log.info("商城 => 购买 - 物品 " + i6 + " 是否为空 " + ((cashItemInfo5 == null) ? 1 : 0));
         }
/*  67 */         if (cashItemInfo5 != null) {
/*  68 */           if (i6 == 92000046) {
/*  69 */             AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买道具.");
             return;
           }
/*  72 */           if (cashItemInfo5.getItemId() / 1000 == 5533 && !cashinfo.hasRandomItem(cashItemInfo5.getItemId())) {
/*  73 */             chr.dropMessage(1, "该道具暂时无法购买，因为找不到对应的箱子信息.");
/*  74 */             c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));



             return;
           }


/*  82 */           if (chr.getCSPoints(n) < cashItemInfo5.getPrice()) {
/*  83 */             chr.dropMessage(1, "点卷余额不足");
/*  84 */             c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
           }
/*  86 */           if (!cashItemInfo5.genderEquals(chr.getGender())) {
/*  87 */             chr.dropMessage(1, "请确认角色名是否错误");
/*  88 */             c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
           }
/*  90 */           if (cs.getItemsSize() >= 100) {
/*  91 */             chr.dropMessage(1, "保管箱已满");
/*  92 */             c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
             return;
           }
/*  95 */           if (cashItemInfo5.getPrice() <= 0) {
/*  96 */             AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买道具.");
             return;
           }
/*  99 */           if (chr.isShowPacket()) {
/* 100 */             log.info("商城 => 购买 - 点卷类型 " + n + " 减少 " + cashItemInfo5.getPrice());
           }
/* 102 */           Item item5 = cs.toItem(cashItemInfo5);
/* 103 */           if (item5 != null && item5.getUniqueId() > 0 && item5.getItemId() == cashItemInfo5.getItemId() && item5.getQuantity() == cashItemInfo5.getCount()) {
/* 104 */             if (ii.isCash(item5.getItemId())) {
/* 105 */               chr.modifyCSPoints(n, -cashItemInfo5.getPrice(), false);
/* 106 */               cs.addToInventory(item5);
/* 107 */               if (n == 1) {
/* 108 */                 item5.setFlag((short)ItemFlag.可以交换1次.getValue());
               }
/* 110 */               c.announce(MTSCSPacket.INSTANCE.购买商城道具(item5, cashItemInfo5.getSN(), c.getAccID()));
/* 111 */               addCashshopLog(chr, cashItemInfo5.getSN(), cashItemInfo5.getItemId(), n, cashItemInfo5.getPrice(), cashItemInfo5.getCount(), chr.getName() + " 购买道具: " + ii.getName(cashItemInfo5.getItemId()));
/* 112 */               if (item5.getItemId() == 5820000) {
/* 113 */                 if (chr.getPotionPot() == null) {
/* 114 */                   MaplePotionPot pot = MaplePotionPot.createPotionPot(chr.getId(), item5.getItemId(), item5.getExpiration());
/* 115 */                   if (pot == null) {
/* 116 */                     chr.dropMessage(1, "创建1个新的药剂罐出现错误.");
/* 117 */                     c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
                     return;
                   }
/* 120 */                   chr.setPotionPot(pot);
                 }
/* 122 */                 c.announce(MTSCSPacket.INSTANCE.updataPotionPot(chr.getPotionPot()));
               }
             } else {
/* 125 */               log.info("[作弊] " + chr.getName() + " 商城非法购买道具.道具: " + item5.getItemId() + " - " + ii.getName(item5.getItemId()));
/* 126 */               AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买道具.");
             }
           } else {
/* 129 */             chr.dropMessage(1, "道具不存在或出现异常，请联系管理员");
           }
         } else {
/* 132 */           chr.dropMessage(1, "不存在的道具，请联系管理员");
         }
/* 134 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 4:
/* 138 */         chr.dropMessage(1, "暂不支持，直接选了点送礼吧！");
/* 139 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;


       case 5:
/* 144 */         chr.clearWishlist();
/* 145 */         if (slea.available() < 40L) {
/* 146 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 149 */         wishlist = new int[12];
/* 150 */         for (i = 0; i < 12; i++) {
/* 151 */           wishlist[i] = slea.readInt();
         }
/* 153 */         chr.setWishlist(wishlist);
/* 154 */         c.announce(MTSCSPacket.INSTANCE.商城购物车(chr, true));
         return;

       case 6:
/* 199 */         m = slea.readByte() + 1;
/* 200 */         i5 = slea.readInt();
/* 201 */         cashItemInfo5 = cashinfo.getItem(i5);
/* 202 */         if (cashItemInfo5 == null) {
/* 203 */           chr.dropMessage(1, "未知错误");
/* 204 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         } else {

/* 207 */           int types = (cashItemInfo5.getItemId() - 9110000) / 1000;
/* 208 */           MapleInventoryType mapleInventoryType = MapleInventoryType.getByType((byte)types);
/* 209 */           if (chr.isShowPacket()) {
/* 210 */             System.out.println("增加道具栏  snCS " + i5 + " 扩充: " + types);
           }
/* 212 */           if (chr.getCSPoints(m) >= 1100 && chr.getInventory(mapleInventoryType).getSlotLimit() < 121) {
/* 213 */             chr.modifyCSPoints(m, -1100, false);
/* 214 */             chr.getInventory(mapleInventoryType).addSlot((short)8);

/* 216 */             c.announce(MTSCSPacket.INSTANCE.扩充道具栏(mapleInventoryType.getType(), chr.getInventory(mapleInventoryType).getSlotLimit()));
           } else {
/* 218 */             chr.dropMessage(1, "扩充失败，点卷余额不足或者栏位已超过上限。");
           }
/* 220 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         }
         return;





       case 7:
/* 229 */         m = slea.readByte() + 1;
/* 230 */         coupon = (slea.readByte() > 0) ? 2 : 1;
/* 231 */         if (chr.getCSPoints(m) >= ((coupon == 2) ? 1100 : 600) && chr.getStorage().getSlots() < 129 - 4 * coupon) {
/* 232 */           chr.modifyCSPoints(m, (coupon == 2) ? -1100 : -600, false);
/* 233 */           chr.getStorage().increaseSlots((byte)(4 * coupon));
/* 234 */           chr.getStorage().saveToDB();

/* 236 */           c.announce(MTSCSPacket.INSTANCE.扩充仓库(chr.getStorage().getSlots()));
         } else {
/* 238 */           chr.dropMessage(1, "仓库扩充失败，点卷余额不足或者栏位已超过上限 96 个位置。");
         }
/* 240 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;




       case 8:
/* 247 */         m = slea.readByte() + 1;
/* 248 */         i4 = slea.readInt();
/* 249 */         cashItemInfo4 = cashinfo.getItem(i4, false);
/* 250 */         slots = c.getAccCharSlots();
/* 251 */         if (cashItemInfo4 == null || cashItemInfo4.getItemId() != 5430000) {
/* 252 */           String str = "角色栏扩充失败，找不到指定的道具信息或者道具ID不正确。";
/* 253 */           if (chr.isAdmin()) {
/* 254 */             str = (cashItemInfo4 == null) ? ("角色栏扩充失败:\r\n找不到道具的信息或者道具没有出售\r\n当前道具的SNid: " + i4) : ("角色栏扩充失败:\r\n道具ID是否正确: " + ((cashItemInfo4.getItemId() == 5430000) ? 1 : 0) + " 当前ID：" + cashItemInfo4.getItemId());
           }
/* 256 */           chr.dropMessage(1, str);
/* 257 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 260 */         if (chr.getCSPoints(m) < cashItemInfo4.getPrice() || slots >= 49) {
/* 261 */           chr.dropMessage(1, "角色栏扩充失败，点卷余额不足或者栏位已超过上限。");
/* 262 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 265 */         if (c.gainAccCharSlot()) {
/* 266 */           chr.modifyCSPoints(m, -cashItemInfo4.getPrice(), false);
/* 267 */           chr.dropMessage(1, "角色栏扩充成功，当前栏位: " + (slots + 1));
         } else {
/* 269 */           chr.dropMessage(1, "角色栏扩充失败。");
         }
/* 271 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;








       case 9:
/* 282 */         chr.dropMessage(1, "暂时不支持。");
/* 283 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;






       case 10:
/* 292 */         m = slea.readByte() + 1;
/* 293 */         sn = slea.readInt();
/* 294 */         cashItemInfo4 = cashinfo.getItem(sn);
/* 295 */         if (cashItemInfo4 == null || chr.getCSPoints(m) < cashItemInfo4.getPrice() * 10 || cashItemInfo4.getItemId() / 10000 != 555) {
/* 296 */           chr.dropMessage(1, "项链扩充失败，点卷余额不足或者出现其他错误。");
/* 297 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 300 */         marr = chr.getQuestNoAdd(MapleQuest.getInstance(122700));
/* 301 */         if (marr != null && marr.getCustomData() != null && Long.parseLong(marr.getCustomData()) >= System.currentTimeMillis()) {
/* 302 */           chr.dropMessage(1, "项链扩充失败，您已经进行过项链扩充。");
         } else {
/* 304 */           long days = 0L;
/* 305 */           if (cashItemInfo4.getItemId() == 5550000) {
/* 306 */             days = 30L;
/* 307 */           } else if (cashItemInfo4.getItemId() == 5550001) {
/* 308 */             days = 7L;
           }
/* 310 */           String customData = String.valueOf(System.currentTimeMillis() + days * 24L * 60L * 60L * 1000L);
/* 311 */           chr.getQuestNAdd(MapleQuest.getInstance(122700)).setCustomData(customData);
/* 312 */           chr.modifyCSPoints(m, -cashItemInfo4.getPrice() * 10, false);
/* 313 */           chr.dropMessage(1, "项链扩充成功，本次扩充花费:\r\n" + ((m == 1) ? "点卷" : "抵用卷") + (cashItemInfo4.getPrice() * 10) + " 点，持续时间为: " + days + " 天。");
         }
/* 315 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 13:
/* 319 */         k = (int)slea.readLong();
/* 320 */         item2 = cs.findByCashId(k);
/* 321 */         if (item2 == null) {
/* 322 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
/* 323 */           if (chr.isShowPacket()) {
/* 324 */             System.out.println("删除商城道具 - 道具为空 删除失败");
           }
           return;
         }
/* 328 */         cs.removeFromInventory(item2);
/* 329 */         c.announce(MTSCSPacket.INSTANCE.商城删除道具(k));
         return;

       case 14:
/* 333 */         item1 = cs.findByCashId((int)slea.readLong());
/* 334 */         if (chr.isShowPacket()) {
/* 335 */           log.info("商城 => 背包 - 道具是否为空 " + ((item1 == null) ? 1 : 0));
         }
/* 337 */         if (item1 == null) {
/* 338 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 341 */         if (chr.getInventory(ItemConstants.getInventoryType(item1.getItemId())).addItem(item1) != -1) {
/* 342 */           cs.removeFromInventory(item1);
/* 343 */           c.announce(MTSCSPacket.INSTANCE.moveItemToInvFormCs(item1));
/* 344 */           if (chr.isShowPacket()) {
/* 345 */             log.info("商城 => 背包 - 移动成功");
           }
         }
         return;

       case 15:
/* 351 */         cashId = (int)slea.readLong();
/* 352 */         itemid = slea.readInt();
/* 353 */         type = MapleInventoryType.getByType(slea.readByte());
/* 354 */         item4 = chr.getInventory(type).findByUniqueId(cashId);
/* 355 */         if (item4 != null && item4.getQuantity() > 0 && item4.getUniqueId() > 0 && chr.getCashInventory().getItemsSize() < 100) {
/* 356 */           Item item_ = item4.copy();
/* 357 */           int i8 = cashinfo.getSnFromId(item_.getItemId());
/* 358 */           chr.getInventory(type).removeItem(item4.getPosition(), item4.getQuantity(), false);
/* 359 */           item_.setPosition((short)0);
/* 360 */           chr.getCashInventory().addToInventory(item_);
/* 361 */           c.announce(MTSCSPacket.INSTANCE.moveItemToCsFromInv(item_, c.getAccID(), i8));
         } else {
/* 363 */           chr.dropMessage(1, "移动失败。");
/* 364 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         }
         return;







       case 31:
/* 375 */         slea.readMapleAsciiString();
/* 376 */         j = 2;
/* 377 */         i3 = (int)slea.readLong();
/* 378 */         item3 = cs.findByCashId(i3);
/* 379 */         if (item3 == null) {
/* 380 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 383 */         i7 = cashinfo.getSnFromId(item3.getItemId());
/* 384 */         cashItemInfo6 = cashinfo.getItem(i7, false);
/* 385 */         if (cashItemInfo6 == null || cashinfo.isBlockRefundableItemId(item3.getItemId())) {
/* 386 */           if (chr.isAdmin()) {
/* 387 */             if (cashItemInfo6 == null) {
/* 388 */               chr.dropMessage(1, "换购失败:\r\n道具是否为空: " + ((cashItemInfo6 == null) ? 1 : 0));
             } else {
/* 390 */               chr.dropMessage(1, "换购失败:\r\n道具禁止回购: " + cashinfo.isBlockRefundableItemId(item3.getItemId()));
             }
           } else {
/* 393 */             chr.dropMessage(1, "换购失败，当前道具不支持换购。");
           }
/* 395 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 398 */         if (!ii.isCash(cashItemInfo6.getItemId())) {
/* 399 */           AutobanManager.getInstance().autoban(chr.getClient(), "商城非法换购道具.");
           return;
         }
/* 402 */         Money = cashItemInfo6.getPrice() / 10 * 3;
/* 403 */         cs.removeFromInventory(item3);
/* 404 */         chr.modifyCSPoints(j, Money, false);
/* 405 */         c.announce(MTSCSPacket.INSTANCE.商城换购道具(i3, Money));
/* 406 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 34:
       case 40:
/* 411 */         slea.readMapleAsciiString();
/* 412 */         slea.skip(1);
/* 413 */         j = 1;
/* 414 */         i2 = slea.readInt();
/* 415 */         cashItemInfo3 = cashinfo.getItem(i2);
/* 416 */         slea.skip(4);
/* 417 */         str1 = slea.readMapleAsciiString();
/* 418 */         str2 = slea.readMapleAsciiString();
/* 419 */         if (cashItemInfo3 == null || !ItemConstants.isEffectRing(cashItemInfo3.getItemId()) || chr.getCSPoints(j) < cashItemInfo3.getPrice() || str2.length() > 73 || str2.length() < 1) {
/* 420 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(0)); return;
         }
/* 422 */         if (!cashItemInfo3.genderEquals(chr.getGender())) {
/* 423 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(7)); return;
         }
/* 425 */         if (chr.getCashInventory().getItemsSize() >= 100) {
/* 426 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(24)); return;
         }
/* 428 */         if (!ii.isCash(cashItemInfo3.getItemId())) {
/* 429 */           AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买戒指道具.");



           return;
         }


/* 437 */         triple1 = MapleCharacterUtil.getInfoByName(str1, chr.getWorld());
/* 438 */         if (triple1 == null || ((Integer)triple1.getLeft()).intValue() <= 0) {
/* 439 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(7));
/* 440 */         } else if (((Integer)triple1.getMid()).intValue() == c.getAccID() || ((Integer)triple1.getLeft()).intValue() == chr.getId()) {
/* 441 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(6));
         } else {
/* 443 */           if (((Integer)triple1.getRight()).intValue() == chr.getGender() && action == 35) {
/* 444 */             c.announce(MTSCSPacket.INSTANCE.商城错误提示(26));
             return;
           }
/* 447 */           int err = MapleRing.createRing(cashItemInfo3.getItemId(), chr, str1, str2, ((Integer)triple1.getLeft()).intValue(), cashItemInfo3.getSN());
/* 448 */           if (err != 1) {
/* 449 */             c.announce(MTSCSPacket.INSTANCE.商城错误提示(1));
             return;
           }
/* 452 */           chr.modifyCSPoints(j, -cashItemInfo3.getPrice(), false);
/* 453 */           c.announce(MTSCSPacket.INSTANCE.商城送礼(cashItemInfo3.getItemId(), cashItemInfo3.getCount(), str1));
/* 454 */           addCashshopLog(chr, cashItemInfo3.getSN(), cashItemInfo3.getItemId(), j, cashItemInfo3.getPrice(), cashItemInfo3.getCount(), chr.getName() + " 购买戒指: " + ii.getName(cashItemInfo3.getItemId()) + " 送给 " + str1);
/* 455 */           chr.sendNote(str1, str1 + " 您已收到" + chr.getName() + "送给您的礼物，请进入现金商城查看！");
/* 456 */           int chz = WorldFindService.getInstance().findChannel(str1);
/* 457 */           if (chz > 0) {
/* 458 */             MapleCharacter receiver = ChannelServer.getInstance(chz).getPlayerStorage().getCharacterByName(str1);
/* 459 */             if (receiver != null) {
/* 460 */               receiver.showNote();
             }
           }
         }
/* 464 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;


       case 35:
/* 469 */         j = slea.readByte() + 1;
/* 470 */         i1 = slea.readInt();
/* 471 */         slea.readInt();
/* 472 */         if (i1 == 10200551 || i1 == 10200552 || i1 == 10200553) {
/* 473 */           chr.dropMessage(1, "当前服务器未开放购买商城活动栏里面的道具.");
/* 474 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));



           return;
         }


/* 482 */         cashItemInfo3 = cashinfo.getItem(i1, false);
/* 483 */         packageIds = null;
/* 484 */         if (cashItemInfo3 != null) {
/* 485 */           packageIds = cashinfo.getPackageItems(cashItemInfo3.getItemId());
         }
/* 487 */         if (cashItemInfo3 == null || packageIds == null) {
/* 488 */           str2 = "未知错误";
/* 489 */           if (chr.isAdmin()) {
/* 490 */             if (cashItemInfo3 == null) {
/* 491 */               str2 = str2 + "\r\n\r\n 礼包道具信息为空";
             }
/* 493 */             if (packageIds == null) {
/* 494 */               str2 = str2 + "\r\n\r\n 礼包道具里面的物品道具为空";
             }
           }
/* 497 */           chr.dropMessage(1, str2);
/* 498 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
         }
/* 500 */         if (chr.getCSPoints(j) < cashItemInfo3.getPrice()) {
/* 501 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(3));
/* 502 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
         }
/* 504 */         if (!cashItemInfo3.genderEquals(c.getPlayer().getGender())) {
/* 505 */           chr.dropMessage(1, "性别不符合");
/* 506 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
         }
/* 508 */         if (c.getPlayer().getCashInventory().getItemsSize() >= 100 - packageIds.size()) {
/* 509 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(24));
/* 510 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 513 */         if (cashItemInfo3.getPrice() <= 0) {
/* 514 */           AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买礼包道具.");
           return;
         }
/* 517 */         chr.modifyCSPoints(j, -cashItemInfo3.getPrice(), false);
/* 518 */         packageItems = new HashMap<>();
/* 519 */         for (iterator = packageIds.iterator(); iterator.hasNext(); ) { int i8 = ((Integer)iterator.next()).intValue();
/* 520 */           CashItemInfo cii = cashinfo.getSimpleItem(i8);
/* 521 */           if (cii == null) {
             continue;
           }
/* 524 */           Item itemz = chr.getCashInventory().toItem(cii);
/* 525 */           if (itemz == null || itemz.getUniqueId() <= 0) {
             continue;
           }








/* 536 */           packageItems.put(Integer.valueOf(i8), itemz);
/* 537 */           chr.getCashInventory().addToInventory(itemz);
/* 538 */           addCashshopLog(chr, i1, itemz.getItemId(), j, cashItemInfo3.getPrice(), itemz.getQuantity(), chr.getName() + " 购买礼包: " + ii.getName(itemz.getItemId()) + " - " + i8); }

/* 540 */         c.announce(MTSCSPacket.INSTANCE.商城购买礼包(packageItems, c.getAccID()));
/* 541 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 36:
/* 545 */         slea.readMapleAsciiString();
/* 546 */         snCsId = slea.readInt();
/* 547 */         cashItemInfo1 = cashinfo.getItem(snCsId);
/* 548 */         partnerName = slea.readMapleAsciiString();
/* 549 */         msg = slea.readMapleAsciiString();
/* 550 */         if (cashItemInfo1 == null || chr.getCSPoints(1) < cashItemInfo1.getPrice() || msg.length() > 73 || msg.length() < 1) {
/* 551 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(3));



           return;
         }


/* 559 */         info = MapleCharacterUtil.getInfoByName(partnerName, chr.getWorld());
/* 560 */         if (info == null || ((Integer)info.getLeft()).intValue() <= 0) {
/* 561 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(7));
/* 562 */         } else if (((Integer)info.getLeft()).intValue() == chr.getId() || ((Integer)info.getMid()).intValue() == c.getAccID()) {
/* 563 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(6));
/* 564 */         } else if (!cashItemInfo1.genderEquals(((Integer)info.getRight()).intValue())) {
/* 565 */           c.announce(MTSCSPacket.INSTANCE.商城错误提示(8));
         } else {
/* 567 */           if (cashItemInfo1.getPrice() <= 0) {
/* 568 */             AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买礼包道具.");
             return;
           }
/* 571 */           chr.getCashInventory().gift(((Integer)info.getLeft()).intValue(), chr.getName(), msg, cashItemInfo1.getSN(), MapleInventoryIdentifier.getInstance());
/* 572 */           chr.modifyCSPoints(1, -cashItemInfo1.getPrice(), false);

/* 574 */           c.announce(MTSCSPacket.INSTANCE.商城送礼包(cashItemInfo1.getItemId(), cashItemInfo1.getCount(), partnerName));
/* 575 */           chr.sendNote(partnerName, partnerName + " 您已收到" + chr.getName() + "送给您的礼物，请进入现金商城查看！");
/* 576 */           addCashshopLog(chr, cashItemInfo1.getSN(), cashItemInfo1.getItemId(), 1, cashItemInfo1.getPrice(), cashItemInfo1.getCount(), chr.getName() + " 赠送礼包给 " + partnerName);
/* 577 */           int chz = WorldFindService.getInstance().findChannel(partnerName);
/* 578 */           if (chz > 0) {
/* 579 */             MapleCharacter receiver = ChannelServer.getInstance(chz).getPlayerStorage().getCharacterByName(partnerName);
/* 580 */             if (receiver != null) {
/* 581 */               receiver.showNote();
             }
           }
         }
/* 585 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 37:
/* 589 */         item = cashinfo.getItem(slea.readInt());
/* 590 */         if (item == null || !MapleItemInformationProvider.getInstance().isQuestItem(item.getItemId())) {
/* 591 */           chr.dropMessage(1, "该道具不是任务物品");
/* 592 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
         }
/* 594 */         if (chr.getMeso() < item.getPrice() || item.getPrice() <= 0) {
/* 595 */           chr.dropMessage(1, "金币不足");
/* 596 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
         }
/* 598 */         if (chr.getItemQuantity(item.getItemId()) > 0) {
/* 599 */           chr.dropMessage(1, "你已经有这个道具\r\n不能购买.");
/* 600 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr)); return;
         }
/* 602 */         if (chr.getInventory(ItemConstants.getInventoryType(item.getItemId())).getNextFreeSlot() < 0) {
/* 603 */           chr.dropMessage(1, "背包空间不足");
/* 604 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));



           return;
         }


/* 612 */         if (item.getItemId() == 4031063 || item.getItemId() == 4031191 || item.getItemId() == 4031192) {
/* 613 */           byte pos = MapleInventoryManipulator.addId(c, item.getItemId(), (short)item.getCount(), null, "商城: 任务物品 在 " + DateUtil.getCurrentDate());
/* 614 */           if (pos < 0) {
/* 615 */             c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
             return;
           }
/* 618 */           chr.gainMeso(-item.getPrice(), false);
/* 619 */           c.announce(MTSCSPacket.INSTANCE.updataMeso(chr));
/* 620 */           c.announce(MTSCSPacket.INSTANCE.商城购买任务道具(item.getPrice(), (short)item.getCount(), pos, item.getItemId()));
         } else {
/* 622 */           AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买任务道具.");
         }
         return;

       case 50:
/* 627 */         slea.readByte();
/* 628 */         snCS = slea.readInt();
/* 629 */         slea.readInt();
/* 630 */         if (snCS == 50200031 && chr.getCSPoints(1) >= 500) {
/* 631 */           chr.modifyCSPoints(1, -500, false);
/* 632 */           chr.modifyCSPoints(2, 500, false);
/* 633 */           chr.dropMessage(1, "兑换抵用卷成功");
/* 634 */         } else if (snCS == 50200032 && chr.getCSPoints(1) >= 1000) {
/* 635 */           chr.modifyCSPoints(1, -1000, false);
/* 636 */           chr.modifyCSPoints(2, 1000, false);
/* 637 */           chr.dropMessage(1, "兑换抵用卷成功");
/* 638 */         } else if (snCS == 50200033 && chr.getCSPoints(1) >= 5000) {
/* 639 */           chr.modifyCSPoints(1, -5000, false);
/* 640 */           chr.modifyCSPoints(2, 5000, false);
/* 641 */           chr.dropMessage(1, "兑换抵用卷成功");
         } else {
/* 643 */           chr.dropMessage(1, "没有找到这个道具的信息。");
         }
/* 645 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 49:
/* 649 */         c.announce(MTSCSPacket.INSTANCE.redeemResponse());
         return;


       case 64:
/* 654 */         uniqueId = slea.readLong();
/* 655 */         boxItem = cs.findByCashId((int)uniqueId);
/* 656 */         if (boxItem == null || !cashinfo.hasRandomItem(boxItem.getItemId())) {
/* 657 */           chr.dropMessage(1, "打开箱子失败，服务器找不到对应的道具信息。");
/* 658 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 661 */         boxItemSNs = cashinfo.getRandomItem(boxItem.getItemId());
/* 662 */         if (boxItemSNs.isEmpty()) {
/* 663 */           chr.dropMessage(1, "打开箱子失败，服务器找不到对应的道具信息。");
/* 664 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 667 */         pair = boxItemSNs.get(Randomizer.nextInt(boxItemSNs.size()));
/* 668 */         cashItemInfo7 = cashinfo.getItem(((Integer)pair.getLeft()).intValue(), false);
/* 669 */         if (cashItemInfo7 != null) {
/* 670 */           Item item5 = cs.toItem(cashItemInfo7);
/* 671 */           if (item5 != null && item5.getUniqueId() > 0 && item5.getItemId() == cashItemInfo7.getItemId() && item5.getQuantity() == cashItemInfo7.getCount()) {
/* 672 */             if (chr.getInventory(ItemConstants.getInventoryType(item5.getItemId())).addItem(item5) != -1) {
/* 673 */               cs.removeFromInventory(boxItem);
/* 674 */               item5.setFlag((short)ItemFlag.可以交换1次.getValue());
/* 675 */               c.announce(MTSCSPacket.INSTANCE.商城打开箱子(item5, Long.valueOf(uniqueId)));
             } else {
/* 677 */               chr.dropMessage(1, "打开箱子失败，请确认背包是否有足够的空间。");
             }
           }
         }
/* 681 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 83:
/* 685 */         slea.skip(1);
/* 686 */         snID = slea.readInt();
/* 687 */         count = slea.readInt();
/* 688 */         cashItemInfo2 = CashItemFactory.getInstance().getItem(snID, false);
/* 689 */         if (cashItemInfo2 == null || count < 1) {
/* 690 */           chr.dropMessage(1, "暂时不能购买该道具。");
/* 691 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 694 */         price = cashItemInfo2.getPrice() * count;
/* 695 */         if (chr.getCSPoints(1) < price) {
/* 696 */           chr.dropMessage(1, "点券不足无法购买。");
/* 697 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 700 */         chr.modifyCSPoints(1, -price);
/* 701 */         chr.modifyCSPoints(2, price);
/* 702 */         c.announce(MTSCSPacket.INSTANCE.抵用券兑换道具());

/* 704 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;

       case 162:
/* 708 */         toCharge = (byte)(slea.readByte() + 1);
/* 709 */         cItem = CashItemFactory.getInstance().getItem(slea.readInt());
/* 710 */         if (cItem == null || chr.getCSPoints(toCharge) < cItem.getPrice() || cItem.getItemId() / 10000 != 504) {
/* 711 */           chr.dropMessage(1, "点券余额不足或者出现其他错误,可能被禁止购买。");
/* 712 */           c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
           return;
         }
/* 715 */         chr.modifyCSPoints(toCharge, -cItem.getPrice(), false);
/* 716 */         chr.set超时空券(chr.get超时空券() + cItem.getCount());
/* 717 */         chr.dropMessage(1, "购买超时空成功\r\n消耗 " + cItem.getPrice() + ((toCharge == 1) ? " 点券" : " 抵用卷") + "\r\n目前超时空券数量为" + chr.get超时空券() + "。");
/* 718 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
         return;
     }

/* 722 */     c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
/* 723 */     System.out.println("商城操作未知的操作类型: 0x" + StringUtil.getLeftPaddedStr(Integer.toHexString(action).toUpperCase(), '0', 2) + " " + slea.toString()); }




   public static void 商城送礼(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 729 */     slea.readMapleAsciiString();
/* 730 */     int snCS = slea.readInt();
/* 731 */     CashItemFactory cashinfo = CashItemFactory.getInstance();
/* 732 */     CashItemInfo item = cashinfo.getItem(snCS);
/* 733 */     MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
/* 734 */     String partnerName = slea.readMapleAsciiString();
/* 735 */     String msg = slea.readMapleAsciiString();
/* 736 */     if (snCS == 92000046) {
/* 737 */       AutobanManager.getInstance().autoban(chr.getClient(), "商城非法购买道具.");



       return;
     }



/* 746 */     if (item == null || chr.getCSPoints(1) < item.getPrice() || msg.length() > 73 || msg.length() < 1) {
/* 747 */       c.announce(MTSCSPacket.INSTANCE.商城错误提示(3));

       return;
     }
/* 751 */     Triple<Integer, Integer, Integer> info = MapleCharacterUtil.getInfoByName(partnerName, chr.getWorld());
/* 752 */     if (info == null || ((Integer)info.getLeft()).intValue() <= 0) {
/* 753 */       c.announce(MTSCSPacket.INSTANCE.商城错误提示(7));
     }
/* 755 */     else if (((Integer)info.getLeft()).intValue() == chr.getId() || ((Integer)info.getMid()).intValue() == c.getAccID()) {
/* 756 */       c.announce(MTSCSPacket.INSTANCE.商城错误提示(6));
     }
/* 758 */     else if (!item.genderEquals(((Integer)info.getRight()).intValue())) {
/* 759 */       c.announce(MTSCSPacket.INSTANCE.商城错误提示(8));
     } else {

/* 762 */       if (!ii.isCash(item.getItemId())) {
/* 763 */         log.info("[作弊] " + chr.getName() + " 商城非法购买礼物道具.道具: " + item.getItemId() + " - " + ii.getName(item.getItemId()));
/* 764 */         chr.dropMessage(1, "购买商城礼物道具出现错误.");
/* 765 */         c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));

         return;
       }
/* 769 */       if (item.getPrice() <= 0) {
/* 770 */         AutobanManager.getInstance().autoban(chr.getClient(), "商城非法赠送礼包道具.");

         return;
       }
/* 774 */       chr.getCashInventory().gift(((Integer)info.getLeft()).intValue(), chr.getName(), msg, item.getSN(), MapleInventoryIdentifier.getInstance());
/* 775 */       chr.modifyCSPoints(1, -item.getPrice(), false);
/* 776 */       c.announce(MTSCSPacket.INSTANCE.商城送礼(item.getItemId(), item.getCount(), partnerName));
/* 777 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
/* 778 */       addCashshopLog(chr, item.getSN(), item.getItemId(), 1, item.getPrice(), item.getCount(), chr.getName() + " 购买道具: " + ii.getName(item.getItemId()) + " 送给 " + partnerName);
/* 779 */       chr.sendNote(partnerName, partnerName + " 您已收到" + chr.getName() + "送给您的礼物，请进入现金商城查看！");
/* 780 */       int chz = WorldFindService.getInstance().findChannel(partnerName);
/* 781 */       if (chz > 0) {
/* 782 */         MapleCharacter receiver = ChannelServer.getInstance(chz).getPlayerStorage().getCharacterByName(partnerName);
/* 783 */         if (receiver != null) {
/* 784 */           receiver.showNote();
         }
       }
     }
   }




   public static void openAvatarRandomBox(LittleEndianAccessor slea, MapleClient c, MapleCharacter chr) {
/* 794 */     if (chr == null) {
       return;
     }
/* 797 */     CashShop cs = chr.getCashInventory();
/* 798 */     Item item = cs.findByCashId((int)slea.readLong());
/* 799 */     if (item == null || item.getItemId() != 5222036) {
/* 800 */       c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
       return;
     }
/* 803 */     chr.dropMessage(1, "当前游戏不支持此功能");
/* 804 */     c.announce(MTSCSPacket.INSTANCE.updateCouponsInfo(chr));
   }

   private static void addCashshopLog(MapleCharacter chr, int SN, int itemId, int type, int price, int count, String itemLog) {
/* 808 */     if (chr == null) {
       return;
     }
/* 811 */     try (DruidPooledConnection con = DatabaseConnection.getInstance().getConnection()) {
/* 812 */       PreparedStatement ps = con.prepareStatement("INSERT INTO cashshop_log (accId, chrId, name, SN, itemId, type, price, count, cash, points, itemlog) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
/* 813 */       ps.setInt(1, chr.getAccountID());
/* 814 */       ps.setInt(2, chr.getId());
/* 815 */       ps.setString(3, chr.getName());
/* 816 */       ps.setInt(4, SN);
/* 817 */       ps.setInt(5, itemId);
/* 818 */       ps.setInt(6, type);
/* 819 */       ps.setInt(7, price);
/* 820 */       ps.setInt(8, count);
/* 821 */       ps.setInt(9, chr.getCSPoints(1));
/* 822 */       ps.setInt(10, chr.getCSPoints(2));
/* 823 */       ps.setString(11, itemLog);
/* 824 */       ps.execute();
/* 825 */       ps.close();
/* 826 */     } catch (SQLException e) {
/* 827 */       log.error("玩家: " + chr.getName() + " ID: " + chr.getId() + " 购买商城道具保存日志出错.", e);
     }
   }
 }


/* Location:              C:\PGX\Server.jar!\handling\cashshop\handler\BuyCashItemHandler.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */